namespace Modbus.IO
{
	/// <summary>
	/// Represents a serial resource.
	/// </summary>
	public interface ISerialResource
	{
		/// <summary>
		/// Indicates that no time-out should occur.
		/// </summary>
		int InfiniteTimeout { get; }
		
		/// <summary>
		/// Gets or sets the number of milliseconds before a time-out occurs when a read operation does not finish.
		/// </summary>
		int ReadTimeout { get; set; }

		/// <summary>
		/// Gets or sets the number of milliseconds before a time-out occurs when a write operation does not finish.
		/// </summary>
		int WriteTimeout { get; set; }

		/// <summary>
		/// Gets or sets the value used to interpret the end of a call to the ReadLine method. 
		/// </summary>
		string NewLine { get; set; }

		/// <summary>
		/// Purges the receive buffer.
		/// </summary>
		void DiscardInBuffer();

		/// <summary>
		/// Reads a number of bytes from the input buffer and writes those bytes into a byte array at the specified offset.
		/// </summary>
		/// <param name="buffer">The byte array to write the input to.</param>
		/// <param name="offset">The offset in the buffer array to begin writing.</param>
		/// <param name="count">The number of bytes to read.</param>
		/// <returns>The number of bytes read.</returns>
		int Read(byte[] buffer, int offset, int count);

		/// <summary>
		/// Reads up to the NewLine value in the input buffer. 
		/// </summary>
		string ReadLine();

		/// <summary>
		/// Writes a specified number of bytes to the port from an output buffer, starting at the specified offset.
		/// </summary>
		/// <param name="buffer">The byte array that contains the data to write to the port.</param>
		/// <param name="offset">The offset in the buffer array to begin writing.</param>
		/// <param name="count">The number of bytes to write.</param>
		void Write(byte[] buffer, int offset, int count);
	}
}
